//
//  BVMyCollectionTool.m
//  BuyVegetable
//
//  Created by zhuzi on 16/12/2.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVMyCollectionTool.h"
#import "BVMycollectionModel.h"
#define KEY_CODE @"code"
#define SUCCESS_CODE @"0"
@implementation BVMyCollectionTool

- (void)fetchmyCollectionSuccess:(void(^)(NSMutableArray *arr))success failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/UserAPI/c_get_usercollection",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"user_id"] = self.user.user_id;
    
    NSMutableArray *arr = [NSMutableArray array];
    [BVHttpRequest postWithUrlString:url parameters:params success:^(id responseObject) {
        NSLog(@"----%@",responseObject);
        if ([responseObject[KEY_CODE] isEqualToString:SUCCESS_CODE]) {
            for (NSMutableDictionary *dic in responseObject[@"result"]) {
                 BVMycollectionModel *mycollectionModel = [[BVMycollectionModel alloc]init];
                 mycollectionModel.ID2 = dic[@"id"];
                 mycollectionModel.all_price = dic[@"all_price"];
                 mycollectionModel.discount = dic[@"discount"];
                 mycollectionModel.good_num = dic[@"goods_num"];
                 mycollectionModel.imgUrl = dic[@"img"];
                 mycollectionModel.is_sales = dic[@"is_sales"];
                 mycollectionModel.number = dic[@"number"];
                 mycollectionModel.status = dic[@"status"];
                 mycollectionModel.title = dic[@"title"];
                 mycollectionModel.unit_price = dic[@"unit_price"];
                 mycollectionModel.weight = dic[@"weight"];
                 mycollectionModel.notice = dic[@"notice"];
                [arr addObject:mycollectionModel];
            }
        }
        if (success) {
            success(arr);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
- (void)delegateCollectionGoods_ID:(NSString *)goods_ID success:(void(^)(NSMutableDictionary *arr))success failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/UserAPI/c_delete_usercollection",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"user_id"] = self.user.user_id;
    params[@"good_id"] = goods_ID;
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [BVHttpRequest postWithUrlString:url parameters:params success:^(id responseObject) {
        NSLog(@"--//--%@",responseObject);
        if ([responseObject[KEY_CODE] isEqualToString:SUCCESS_CODE]) {
            dic[@"code"] = responseObject[@"code"];
            dic[@"msg"] = responseObject[@"msg"];
        }
        if (success) {
            success(dic);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
- (void)addShoppingCartGoods_idArr:(NSMutableArray *)goods_idArr success:(void(^)(NSMutableDictionary *arr))success failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/GoodsAPI/c_add_shopcart",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"user_id"] = self.user.user_id;

    NSMutableString * goods_id;
    for (int i = 0; i < goods_idArr.count; i++) {
        [goods_id stringByAppendingString:@"%|"];
    }
    
    NSLog(@"-------这是---%@",goods_id);
    
//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [BVHttpRequest postWithUrlString:url parameters:params success:^(id responseObject) {
        NSLog(@"--//--%@",responseObject);
        if (success) {
            
        }
    } failure:^(NSError *error) {
        if (failure) {
            
        }
    }];
}
@end
